package com.shigen.demo.bean;

import com.shigen.demo.Enum.HttpStatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result<T> {

  private Integer status;
  private String msg;
  private T data;

  public static <T> Result<T> ok(T data, String msg) {
    return new Result(200, msg, data);
  }

  public static <T> Result<T> ok(String msg) {
    return new Result(200, msg, null);
  }

  public static <T> Result<T> ok(T data) {
    return new Result(200, null, data);
  }

  public static <T> Result<T> err(T data, String msg) {
    return new Result(400, msg, data);
  }

  public static <T> Result<T> err(String msg) {
    return new Result(400, msg, null);
  }

  public Result(Integer status, String msg) {
    this.status = status;
    this.msg = msg;
  }

  public Result(Integer status, T data) {
    this.status = status;
    this.data = data;
  }

  public Result(HttpStatusCode httpStatusCode) {
    this.status = httpStatusCode.getCode();
    this.msg = httpStatusCode.getZhMessage();
  }
}
